def weather_forecast():
    # 基础概率
    P_rain = 0.2          # 下雨概率20%
    P_no_rain = 0.8       # 不下雨概率80%
    
    # 条件概率
    P_clouds_if_rain = 0.8     # 下雨时乌云概率
    P_clouds_if_no_rain = 0.3  # 不下雨时乌云概率
    
    #观察到乌云
    P_clouds = (P_clouds_if_rain * P_rain + 
               P_clouds_if_no_rain * P_no_rain)
    
    # 贝叶斯更新
    P_rain_if_clouds = (P_clouds_if_rain * P_rain) / P_clouds
    
    return P_rain_if_clouds

rain_prob = weather_forecast()
print(f"观察到乌云时下雨概率: {rain_prob:.2%}")